<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <el-input v-model="query.name" clearable size="small" placeholder="输入机构名称" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
        <el-select v-model="query.status" style="width: 200px;" class="filter-item">
            <el-option v-for="item in dict.apply_status" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
        <rrOperation />
      </div>
    </div>
    <!--表格渲染-->

        <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%"
            @selection-change="crud.selectionChangeHandler">
            <el-table-column type="selection" width="55" />
            <el-table-column prop="headPic" label="头像" >
                <template slot-scope="scope">
                    <el-image style="width: 50px; height: 50px" :src="scope.row.headPic" fit="cover"></el-image>
                </template>
            </el-table-column>
            <el-table-column prop="name" label="机构名称" />
            
            <el-table-column prop="addressInfo" label="机构地址" />
            <el-table-column prop="middleAmount" label="中学人数" />
            <el-table-column prop="primaryAmount" label="小学人数" />
            <el-table-column prop="kindergartenAmount" label="幼儿园人数" />
            <el-table-column prop="mobile" label="手机号" />
            <el-table-column prop="createTime" label="申请时间" />
            <el-table-column prop="teachingPrice" label="课时费" />
            <el-table-column prop="status" label="审核状态" >
                <template slot-scope="scope">
                    <el-tag type="primary" v-if="scope.row.status == 0">未审核</el-tag>
                    <el-tag type="success" v-if="scope.row.status == 1">已审核</el-tag>
                    <el-tag type="danger" v-if="scope.row.status == 2">已驳回</el-tag>
                </template>
            </el-table-column>
            <el-table-column  label="操作" width="150px"
                align="center">
                <template slot-scope="scope">
                    <el-button type="text" @click="audit(scope.row.id,1)" v-if="scope.row.status == 0">通过</el-button>
                    <el-button style="color: red;" type="text" @click="audit(scope.row.id,2)" v-if="scope.row.status == 0">驳回</el-button>
                </template>
            </el-table-column>
        </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import crudJob from '@/api/system/timing'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import { auditingApply} from '@/api/mini/user'
const defaultForm = { id: null, jobName: null, subTask: null, beanName: null, methodName: null, params: null, cronExpression: null, pauseAfterFailure: true, isPause: false, personInCharge: null, email: null, description: null }
export default {
  name: 'Timing',
    dicts: ['apply_status'],
  components: {  pagination, crudOperation, rrOperation },
  cruds() {
    return CRUD({ title: '用户列表', url: 'api/user/applyList',listMethod: 'post', listKey: ['data', 'list'], crudMethod: { ...crudJob }})
  },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  data() {
    return {
      delLoading: false,
      permission: {
        add: ['admin', 'timing:add'],
        edit: ['admin', 'timing:edit'],
        del: ['admin', 'timing:del']
      },
    }
  },
  methods: {
    audit(id,status){
      const msg = status == 1 ? '通过' : '驳回'
      this.$confirm(`是否确认审核${msg}？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        auditingApply({id:id,status:status}).then(res=>{
          this.$message.success('操作成功')
          this.toQuery()
        })
      }).catch(() => {
        this.$message.info('已取消操作')
      });
    }
  }
}
</script>
